<script setup>
import { ref, watchEffect } from 'vue';
import { getBrandByCategoryIdApi } from'@/apis/pms/brandRelate.js'


const props = defineProps({
    categoryId:{
        type:Number,
    },
    brandId:{
        type:Number,
    },
})

const id=ref(props.brandId)
const emits = defineEmits(['update:brandId'])
const selectData = ref([])
watchEffect(async()=>{
    if(props.categoryId !== null && props.categoryId !== void 0 && props.categoryId!==''){
        const res = await getBrandByCategoryIdApi(props.categoryId);
        selectData.value = res.data;
    }else{
        selectData.value = [];
        id.value='';
        emits('update:brandId',id.value);
    }
})

const handleChange=()=>{
    emits('update:brandId',id.value);
}

</script>

<template>
    <el-select v-model="id" clearable placeholder="请选择品牌名" @change="handleChange">
      <el-option
        v-for="item in selectData"
        :key="item.id"
        :label="item.name"
        :value="item.id"
      />
  </el-select>
</template>

<style scoped lang='scss'>

</style>